package com.lt.bcra.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
/**
 * 业务层自动填充某些固定属性
 */
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    //数据自动填充
    public void insertFill(MetaObject metaObject) {
        log.info("创建时间和修改时间创建时候自动填充");
        this.strictInsertFill(metaObject,"createTime", LocalDateTime.class,LocalDateTime.now());
        this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class,LocalDateTime.now());

        log.info("用户状态创建时候自动填充");
        this.strictInsertFill(metaObject,"status", String.class,"activation");

        log.info("用户逻辑删除标识创建时候自动填充");
        this.strictInsertFill(metaObject,"deleted", Boolean.class,false);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("修改时间修改时候自动填充");
        this.strictInsertFill(metaObject,"updateTime", LocalDateTime.class,LocalDateTime.now());
    }

}
